<template>
  <div class="aui-card-list">
    <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}"
      @searchReset="searchReset()">
      <el-col :span="5">
        <el-form-item label="预警项">
          <el-select v-model="dataForm.eventCode" placeholder="请选择..." filterable clearable>
            <el-option v-for="(item,index) in eventList" :key="index" :label="item.eventName" :value="item.eventCode">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="5">
        <el-form-item label="业务单号">
          <el-input v-model="dataForm.refCode" placeholder="业务单号" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="10">
        <el-form-item label="日期范围">
          <el-date-picker v-model="dataForm.createDateB" type="date" placeholder="开始日期" style="width:130px;"
            value-format="yyyy-MM-dd">
          </el-date-picker>-
          <el-date-picker v-model="dataForm.createDateE" type="date" placeholder="截止日期" style="width:130px;"
            value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
      </el-col>
    </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar :custom="{immediate:true}">
        <!-- <template v-slot:buttons>
          <el-button v-if="$hasPermission('msg:msgBizContentLog:save')" type="primary" @click="addOrUpdateHandle()">{{
            $t('add') }}</el-button>
          <el-button v-if="$hasPermission('msg:msgBizContentLog:delete')" type="danger" @click="deleteHandle()">{{
            $t('deleteBatch') }}</el-button>
        </template> -->
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
          <el-dropdown trigger="click" style="padding-left: 5px;" placement="bottom">
            <el-button icon="el-icon-download" circle>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item icon="el-icon-bottom" @click.native="exportHandle(true)">导出当前页</el-dropdown-item>
              <el-dropdown-item icon="el-icon-download" @click.native="exportHandle()">全部导出
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </vxe-toolbar>
      <div class="aui-card-list-body-table">
        <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" :height="this.tableHeight"
          auto-resize :sort-config="{trigger:'cell'}" @sort-change="sortChange" @select-change="dataListSelectionChangeHandleVex"
          @select-all="dataListSelectionAllChangeHandleVex" :data="dataList" max-height="auto">
          <vxe-table-column field="fid" title="事件ID" :visible="false" width="120">
          </vxe-table-column>
          <vxe-table-column field="extendId" title="消息发送ID">
          </vxe-table-column>
          <vxe-table-column field="eventCode" title="预警项" min-width="100">
            <template slot-scope="scope">
              {{$getDataItem(eventList,scope.row.eventCode,'eventCode').eventName}}
            </template>
          </vxe-table-column>
          <vxe-table-column field="refCode" title="业务单号"> </vxe-table-column>
          <vxe-table-column field="remark" title="业务内容"> </vxe-table-column>
          <vxe-table-column field="ruleId" title="规则ID" :visible="false">
          </vxe-table-column>
          <vxe-table-column field="ruleTitle" title="规则名称">
          </vxe-table-column>
          <vxe-table-column field="status" title="队列投递" width="70" align="center">
            <template slot-scope="scope">
              <el-tag type="success" v-if="scope.row.status===1">成功</el-tag>
              <el-tag type="danger" v-else>失败</el-tag>
            </template>
          </vxe-table-column>
          <vxe-table-column field="sendRemark" title="消息参数"> </vxe-table-column>
          <vxe-table-column field="bizSendStatus" title="发送状态" width="90" align="center">
            <template slot-scope="scope">
              <el-tag type="success" v-if="scope.row.bizSendStatus===0">未发送</el-tag>
              <el-tag type="success" v-if="scope.row.bizSendStatus===1">发送中</el-tag>
              <el-tag type="success" v-if="scope.row.bizSendStatus===2">发送成功</el-tag>
              <el-tag type="danger" v-else>发送失败</el-tag>
            </template>
          </vxe-table-column>
          <vxe-table-column field="bizSendTime" title="发送时间"> </vxe-table-column>
          <vxe-table-column field="bizSendDesc" title="状态描述"> </vxe-table-column>
          <!-- <vxe-table-column field="updater" title="更新者" :visible="false">
          </vxe-table-column>
          <vxe-table-column field="updateDate" title="最后更新时间" align="center" header-align="center">
          </vxe-table-column> -->
          <!-- <vxe-table-column title="handle" width="120" show-overflow="false" fixed="right" align="center">
        <template slot-scope="scope">
          <el-button v-if="$hasPermission('msg:msgBizContentLog:update')" type="text" size="small" icon="el-icon-edit"
            @click="addOrUpdateHandle(scope.row)">{{ $t('update') }}</el-button>
          <el-button v-if="$hasPermission('msg:msgBizContentLog:delete')" type="text" size="small" icon="el-icon-delete"
            @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
        </template>
      </vxe-table-column> -->
        </vxe-table>
        <el-pagination :current-page="page" :page-sizes="pageSizes" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import moment from 'moment'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      moment: moment,
      searchShow: true,
      mixinViewModuleOptions: {
        getDataListURL: '/msg/msgBizContentLog/page',
        getDataListIsPage: true,
        deleteURL: '/msg/msgBizContentLog',
        deleteIsBatch: true,
        exportURL: '/msg/msgBizContentLog/export'
      },
      headLock: true,
      eventList: [],
      dataForm: {
        fid: '',
        extendId: '',
        eventCode: '',
        ruleId: '',
        ruleTitle: '',
        status: '',
        createDateB: moment(new Date()).add(-1, 'd').format('YYYY-MM-DD'),
        createDateE: ''
      }
    }
  },
  created () {
    this.loadEventList()
  },
  components: {
  },
  methods: {
    loadEventList () {
      this.$http.get('/msg/msgBizEvent/list', { params: { flag: 1 } }).then(({ data: res }) => {
        this.eventList = res.data
      })
    },
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    }
  }
}
</script>
